package com.ruoyi.algorithm.controller;

import com.ruoyi.algorithm.entity.AlgorithmType;
import com.ruoyi.algorithm.entity.AlgorithmTypeGroup;
import com.ruoyi.algorithm.model.AlgorithmTypeModel;
import com.ruoyi.algorithm.service.AlgorithmTypeService;
import com.beihu.sightplus.common.response.ErrorMsgType;
import com.beihu.sightplus.common.response.PageResult;
import com.beihu.sightplus.common.response.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author dyk
 * @date 2021/7/16 13:12
 * @description
 */
@RestController
@Api(value = "算法类型",tags = "算法类型")
@RequestMapping("algorithmType")
public class AlgorithmTypeController {
    @Resource
    private AlgorithmTypeService algorithmTypeService;

    @ApiOperation("分页查询算法类型组")
    @GetMapping("listAlgorithmTypeGroup")
    public ResultData listAlgorithmTypeGroup(AlgorithmTypeModel pageRequest) {
        PageResult page = algorithmTypeService.listAlgorithmTypeGroup(pageRequest);

        return ResultData.success(page);
    }

    @ApiOperation("添加算法分类")
    @PostMapping("addAlgorithmTypeGroup")
    public ResultData addAlgorithmTypeGroup(@RequestBody AlgorithmTypeGroup algorithmTypeGroup){
        boolean result = algorithmTypeService.addAlgorithmTypeGroup(algorithmTypeGroup);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }
    @ApiOperation("添加算法类型")
    @PostMapping("addAlgorithmType")
    public ResultData addAlgorithmType(@RequestBody AlgorithmType algorithmType){
        boolean result = algorithmTypeService.addAlgorithmType(algorithmType);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }

    @ApiOperation("删除算法分类")
    @DeleteMapping("deleteAlgorithmTypeGroup")
    public ResultData deleteAlgorithmTypeGroup(Long id){
        boolean result = algorithmTypeService.deleteAlgorithmTypeGroup(id);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }

    @ApiOperation("删除算法类型")
    @DeleteMapping("deleteAlgorithmType")
    public ResultData deleteAlgorithmType(Long id){
        boolean result = algorithmTypeService.deleteAlgorithmType(id);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }


    @ApiOperation("算法类型详情")
    @GetMapping("detailAlgorithmType")
    public ResultData detailAlgorithmType(Long id){
        AlgorithmType algorithmType = algorithmTypeService.detailAlgorithmType(id);
        return ResultData.success(algorithmType);

    }
    @ApiOperation("算法分类详情")
    @GetMapping("detailAlgorithmTypeGroup")
    public ResultData detailAlgorithmTypeGroup(Long id){
        AlgorithmTypeGroup algorithmTypeGroup = algorithmTypeService.detailAlgorithmTypeGroup(id);
        return ResultData.success(algorithmTypeGroup);
    }

    @ApiOperation("修改算法类型")
    @PutMapping("updateAlgorithmType")
    public ResultData updateAlgorithmType(@RequestBody AlgorithmType algorithmType){
        boolean result = algorithmTypeService.updateAlgorithmType(algorithmType);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }

    @ApiOperation("修改算法分类")
    @PostMapping("updateAlgorithmTypeGroup")
    public ResultData updateAlgorithmTypeGroup(@RequestBody AlgorithmTypeGroup algorithmTypeGroup){
        boolean result = algorithmTypeService.updateAlgorithmTypeGroup(algorithmTypeGroup);
        if (result){
            return ResultData.success();
        }else{
            return ResultData.error(ErrorMsgType.Fail);
        }
    }




}
